home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample PMSAM / PMSAM Framework / Common / FileUtils.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-28  |  5.3 KB  |  231 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        FileUtils.h
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Written by:    Tim Harnett
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         <11>     4/5/95        HDA        fix DoGet's check for folders. Now checks for ioDirMask
  13.         <10>     1/11/95    TMH        added Write(StringPtr pascalString)
  14.          <8>    10/20/94    TMH        added Exists()
  15.          <7>    10/14/94    TMH        some file id methods
  16.          <6>    10/13/94    TMH        added Delete()
  17.          <5>     10/6/94    TMH        SetFSSpec does not return an error
  18.          <4>     10/3/94    TMH        added SetType and SetCreator
  19.          <3>     9/30/94    TMH        added CFolderIterator
  20.          <2>     9/27/94    TMH        added CFSSpec, CFolder and CFile descend from CFSSpec
  21.          <1>     9/20/94    TMH        Abandon RoadsideRest embrace Mercury
  22.          <4>     9/20/94    TMH        added overloaded Write(char* str) method
  23.          <3>      9/9/94    TMH        more methods for
  24.          <2>     6/14/94    TMH        methods for opening closeing, writing
  25.                  4/18/94    TMH        xxx put comment here xxx
  26.  
  27.     To Do:
  28. */
  29.  
  30.  
  31. #ifndef __FileUtils__
  32. #define __FileUtils__
  33.  
  34.  
  35. #ifndef __TYPES__
  36. #include "Types.h"
  37. #endif
  38.  
  39. #ifndef __FILES__
  40. #include "Files.h"
  41. #endif
  42.  
  43. #ifndef __FOLDERS__
  44. #include "Folders.h"
  45. #endif
  46.  
  47. #ifndef __PASCALSTRING__
  48. #include "PascalString.h"
  49. #endif
  50.  
  51. #ifndef __MEMORY__
  52. #include "Memory.h"
  53. #endif
  54.  
  55. class CRString32;
  56.  
  57. const kDataExceedsBufLen = 100;
  58.  
  59.  
  60. //--------------------------------------
  61. //        C F S S p e c
  62. //--------------------------------------
  63.  
  64. class    CFSSpec {
  65. public:
  66.     
  67.                 CFSSpec() {memset(&fFSSpec,0,sizeof(FSSpec));}
  68.                 CFSSpec(HFileInfo* infoPB);
  69.                 CFSSpec(short vRefNum,long parentdDirID,StringPtr name);
  70.                 CFSSpec(short vRefNum,long parentdDirID,char* name);
  71.  
  72.     void        SetFSSpec(short vRefNum,long dirID,StringPtr name);
  73.     void        SetName(StringPtr newName) { BlockMove(newName,fFSSpec.name,newName[0]+1); }
  74.  
  75.     OSErr        GetCatInfo(CInfoPBRec& cInfo);
  76.     OSErr        SetCatInfo(CInfoPBRec& cInfo);
  77.  
  78.     StringPtr    NamePtr() { return (StringPtr) &fFSSpec.name; }
  79.     short        VRefNum() { return fFSSpec.vRefNum; }
  80.     long        ParID()        { return fFSSpec.parID; }
  81.     
  82.     FSSpec        fFSSpec;
  83.  
  84. };
  85.  
  86. //--------------------------------------
  87. //        C F i l e
  88. //--------------------------------------
  89.  
  90. class    CFile : public CFSSpec {
  91. public:
  92.                 CFile();
  93.                 CFile(short vRefNum,long parentdDirID,StringPtr name);
  94.                 CFile(short vRefNum,long parentdDirID,char* name);
  95.                 CFile(HFileInfo* infoPB);
  96.                 
  97.         //-----------------
  98.         //    Accessors
  99.         //-----------------
  100.         
  101.     
  102.     OSErr        GetPhysicalSize(long& dataSize, long& rsrcSize);
  103.     OSErr        GetFileInfo(HParamBlockRec& pb);
  104.     
  105.     
  106.     long        GetPosition();
  107.     long        GetSize();
  108.  
  109.     void        SetPosition(long newPosition);
  110.     void         SetToStartOfLine(char lineTerminator=0x0d);
  111.  
  112.     Boolean        Exists();
  113.     Boolean        IsOpen()     { return fRefNum != 0; }
  114.  
  115.  
  116.     OSErr        Delete();
  117.         //    Create
  118.         
  119.         
  120.     OSErr        Create(OSType fileCreator, OSType fileType);
  121.     OSErr        Open(char permission);
  122.     OSErr        OpenResourceFork(char permission);
  123.     OSErr        Close();
  124.  
  125.  
  126.         //    Writing
  127.         
  128.         
  129.     OSErr        Write(void* data,long dataLen);
  130.     OSErr        Write(char* c);            // write 'C' string.
  131.     OSErr        Write(StringPtr pascalString);            // write Pascal string.
  132.  
  133.  
  134.         //    Reading
  135.         
  136.         
  137.     OSErr        Read(void* data,long* dataLen);
  138.     char        ReadByte();
  139.     long        ReadLine(char* lineBuf,long maxChars,char lineTerminator=0x0d);
  140.     long         ReadUntilChar(void* buf,long* dataLen,char tillChar);
  141.  
  142.  
  143.         //    File Info
  144.     
  145.     long        GetCreationDate();
  146.     long        GetModificationDate();
  147.     
  148.     OSErr        SetType(OSType fileType);
  149.     OSErr        SetCreator(OSType fileCreator);
  150.     OSErr        SetCreatorAndType(OSType fileCreator,OSType fileType);
  151.  
  152.  
  153.     OSErr        GetFileID(long* fileID );
  154.  
  155. private:
  156.     short    fRefNum;        // != 0 when file open
  157. };
  158.  
  159.  
  160. //--------------------------------------
  161. //        C F o l d e r
  162. //--------------------------------------
  163. class CFolder : public CFSSpec  {
  164. public:
  165.             CFolder() { fDirID = 0; };
  166.             CFolder(OSType folderType);
  167.             CFolder(short vRefNum,long parentdDirID,StringPtr name);
  168.             CFolder(short vRefNum,long parentdDirID,char* name);
  169.  
  170.     OSErr    CreateFolder();
  171.     OSErr    GetDirInfo(DirInfo& dirInfoPB);
  172.     long    DirID() { return fDirID; };
  173.     
  174.     long    fDirID;
  175.     
  176.     OSType    fFolderType;
  177. };
  178.  
  179.  
  180. //----------------------------------
  181. //    C F o l d e r I t e r a t o r
  182. //-----------------------------------
  183.  
  184. //    Use this to iterate over all the files in a
  185. //    folder.
  186.  
  187. class CFolderIterator {
  188. public:
  189.     enum ItemFilter {
  190.         kFilesAndFolders = 0,
  191.         kFilesOnly,
  192.         kFoldersOnly
  193.     };
  194.         CFolderIterator(CFolder& folder,CFolderIterator::ItemFilter itemFilter);
  195.         HFileInfo*    FirstFile();
  196.         Boolean        More() { return fCatInfo->ioResult == 0; };
  197.         HFileInfo*    NextFile();
  198.         OSErr        IOResult() { return fCatInfo->ioResult; } 
  199. private:
  200.         void        DoGet();
  201.         
  202.         
  203.         short        fVRefNum;
  204.         long        fDirID;
  205.         CInfoPBRec    fCatInfoPB;
  206.         HFileInfo*    fCatInfo;
  207.         Str255        fNameBuf;
  208.         short        fIndex;
  209.         
  210.         ItemFilter    fItemFilter;
  211. };
  212.  
  213.  
  214. //------------------------------------
  215.  
  216. extern OSErr SearchFolder(short vRefNum, long dirID, Boolean (*DoEachFile)(HFileInfo* filePB,void* refCon), void* refCon );
  217. extern Boolean FindAnyFile(HFileInfo* filePB,void* refCon);
  218. extern OSErr FindFolder(CFolder* folder);
  219. extern Boolean FindFileByName(short vRefNum, long dirID, CFile* fileToFind);
  220.  
  221. extern Boolean __FindFolder(HFileInfo* filePB,void* refCon);
  222.  
  223. extern OSErr FocHFSHeirarchy(OSType folderParentType,char* pathName,CFolder& lastChild);
  224. extern OSErr FocHFSHeirarchyFromResource(short resId,CFolder& lastChild);
  225.  
  226. extern int ParseHFSPath(char* pathName,char** folderList);
  227.  
  228. OSErr ExchangeFileIDs(CFile& srcFile,CFile& destFile);
  229.  
  230. #endif __FileUtils__
  231.